﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public enum ShaType
{
    None,

    /// <summary>
    /// 差值
    /// </summary>
    Cha,

    /// <summary>
    /// 质数
    /// </summary>
    ZhiShu,

    /// <summary>
    /// 合数
    /// </summary>
    HeShu,

    /// <summary>
    /// 和值
    /// </summary>
    HeZhi,

    /// <summary>
    /// 奇数
    /// </summary>
    JiShu,

    /// <summary>
    /// 偶数
    /// </summary>
    OuShu,
}

public class conditionSha : MonoBehaviour
{
    private void Awake()
    {
        gameObject.SetActive(false);
    }

    // Start is called before the first frame update
    void Start()
    {
        UIController.instance.Get("Cha_Toggle").GetComponent<UnityEngine.UI.Toggle>().isOn = false;
        UIController.instance.Get("ZhiHe_Toggle").GetComponent<UnityEngine.UI.Toggle>().isOn = false;
        UIController.instance.Get("He_Toggle").GetComponent<UnityEngine.UI.Toggle>().isOn = false;
        UIController.instance.Get("Sum_Toggle").GetComponent<UnityEngine.UI.Toggle>().isOn = false;
        UIController.instance.Get("JiShu_Toggle").GetComponent<UnityEngine.UI.Toggle>().isOn = false;
        UIController.instance.Get("Ou_Toggle").GetComponent<UnityEngine.UI.Toggle>().isOn = false;
//        UIController.instance.Get("").GetComponent<UnityEngine.UI.Toggle>().isOn = false;

        UIController.instance.Get("closeBtn").GetComponent<Button>().onClick.AddListener(() =>
        {
            gameObject.SetActive(false);
        });


        UIController.instance.Get("TijiaoShaBtn").GetComponent<Button>().onClick.AddListener(() =>
        {
            if (UIController.instance.Get("Cha_Toggle").GetComponent<Toggle>().isOn == true)
            {
                var text = UIController.instance.Get("Cha_Input").GetComponent<InputField>().text;
                int num = 0;
                text = text.Trim();
                if (text == string.Empty || text == "")
                {
                    return;
                }

                int.TryParse(text, out num);
                UIController.instance.Get("ShuangseQiu").GetComponent<ShaProList>()
                    .StartShaBall(new List<int>(), num, ShaType.Cha);
            }
            else if (UIController.instance.Get("ZhiHe_Toggle").GetComponent<Toggle>().isOn == true)
            {
                var text = UIController.instance.Get("ZhiHe_Input").GetComponent<InputField>().text;
                int num = 0;
                text = text.Trim();
                if (text == string.Empty || text == "")
                {
                    return;
                }

                int.TryParse(text, out num);
                UIController.instance.Get("ShuangseQiu").GetComponent<ShaProList>()
                    .StartShaBall(new List<int>(), num, ShaType.ZhiShu);
            }
            /// 合数
            else if (UIController.instance.Get("He_Toggle").GetComponent<Toggle>().isOn == true)
            {
                var text = UIController.instance.Get("He_Input").GetComponent<InputField>().text;
                int num = 0;
                text = text.Trim();
                if (text == string.Empty || text == "")
                {
                    return;
                }

                int.TryParse(text, out num);
                UIController.instance.Get("ShuangseQiu").GetComponent<ShaProList>()
                    .StartShaBall(new List<int>(), num, ShaType.HeShu);
            }
            else if (UIController.instance.Get("Sum_Toggle").GetComponent<Toggle>().isOn == true)
            {
                var text = UIController.instance.Get("Sum_Input").GetComponent<InputField>().text;
                int num = 0;
                text = text.Trim();
                if (text == string.Empty || text == "")
                {
                    return;
                }

                int.TryParse(text, out num);
                UIController.instance.Get("ShuangseQiu").GetComponent<ShaProList>()
                    .StartShaBall(new List<int>(), num, ShaType.HeZhi);
            }
            ///奇数 JiShu_Toggle
            else if (UIController.instance.Get("JiShu_Toggle").GetComponent<Toggle>().isOn == true)
            {
                var text = UIController.instance.Get("JiShu_Input").GetComponent<InputField>().text;
                int num = 0;
                text = text.Trim();
                if (text == string.Empty || text == "")
                {
                    return;
                }

                int.TryParse(text, out num);
                UIController.instance.Get("ShuangseQiu").GetComponent<ShaProList>()
                    .StartShaBall(new List<int>(), num, ShaType.JiShu);
            }
//            SumShu Ou_Toggle
            else if (UIController.instance.Get("Ou_Toggle").GetComponent<Toggle>().isOn == true)
            {
                var text = UIController.instance.Get("Ou_Input").GetComponent<InputField>().text;
                int num = 0;
                text = text.Trim();
                if (text == string.Empty || text == "")
                {
                    return;
                }

                int.TryParse(text, out num);
                UIController.instance.Get("ShuangseQiu").GetComponent<ShaProList>()
                    .StartShaBall(new List<int>(), num, ShaType.OuShu);
            }

            gameObject.SetActive(false);
        });
    }
}